*******************************************************************************************************
* Landmines Analysis for Contractual Landmines (Scott, Choi, Gulati 2023)
*
*******************************************************************************************************


****************************************************************************

clear all

set memory 5g
set matsize 1200
set more off

** Change pathdata to local folder for stata do and dta files
local pathdata "[INSERT FILE PATHDATA]"


** Load Dataset

use "`pathdata'/sovereign data.dta", clear


****************************************************************************
****************************************************************************
* Tests
****************************************************************************
****************************************************************************
* Historical Holdovers -- look at persistence (analysis at p. 51 in text)

* Buy back persistence
gen temp = buyback * (period=="1990-1995")
bysort sovid: egen bbexist = max(temp)
drop temp
tabulate sovid buyback if period=="2020-2022" & bbexist==1

* negative pledge persistence
gen temp = neg_pledge * (period=="1990-1995")
bysort sovid: egen npexist = max(temp)
drop temp
tabulate sovid neg_pledge if period=="2020-2022" & npexist==1

* pari passu persistence
gen temp = pari_passu * (period=="1990-1995")
bysort sovid: egen ppexist = max(temp)
drop temp
tabulate sovid pari_passu if period=="2020-2022" & ppexist==1


* chi2 test of difference in distribution for the 4 historical holdout clauses
tabi 7 4 \ 7 2 \ 14 0, row chi2


****************************************************************************
****************************************************************************

** Test for text of paper
tabulate num_subacc high_wealth, col chi2
ttest num_subacc, by(high_wealth)

** Table 4
eststo, title("Model 1"):  regress num_subacc low_wealth2019 english_law other_law topatty_issuer topatty_uw  if period=="2020-2022", cluster(sovid)
esttab using "`pathdata'/Table 4.rtf", pr2 ar2 star(+ 0.10 * 0.05 ** 0.01) rtf title("Table X") replace
eststo clear

*robustness indicator variable for sovereigns in the World Bank 2019 GNI per capita ranking top 20
regress num_subacc low_wealth20_2019 english_law other_law topatty_issuer topatty_uw  if period=="2020-2022", cluster(sovid)

*robustness with indicator variable for sovereigns in the World Bank 2019 GNI per capita ranking top 30
regress num_subacc low_wealth2000 english_law other_law topatty_issuer topatty_uw  if period=="2020-2022", cluster(sovid)

*robustness with the addition of the log of the offering amount in billions of US dollars and the maturity length of the bond in years as independent variables
regress num_subacc low_wealth english_law other_law topatty_issuer topatty_uw lnoamt mat_length if period=="2020-2022", cluster(sovid)



****************************************************************************
****************************************************************************
*** Tests between the periods

gen ptime = 0
replace ptime=1 if period=="1960-85"
replace ptime=2 if period=="1990-1995"
replace ptime=3 if period=="2020-2022"


* Table 2.  Historical Holdover Comparison
tabulate ptime neg_pledge if (ptime==2) | (ptime==3), chi2 row
tabulate ptime buyback if (ptime==2) | (ptime==3), chi2 row
tabulate ptime pari_passu if (ptime==2) | (ptime==3), chi2 row

* Table 3.  Subversive Accretion Comparison
tabulate ptime fiscal_laws if (ptime==2) | (ptime==3), chi2 row
tabulate ptime jurisdiction if (ptime==2) | (ptime==3), chi2 row
tabulate ptime sovereign_immunity_bylaw if (ptime==2) | (ptime==3), chi2 row
tabulate ptime pari_passu_mandlaw if (ptime==2) | (ptime==3), chi2 row
tabulate ptime prescription if (ptime==2) | (ptime==3), chi2 row
tabulate ptime glaw_authexec if (ptime==2) | (ptime==3), chi2 row
tabulate ptime sovereign_immunity_exclusion if (ptime==2) | (ptime==3), chi2 row
tabulate ptime manifest_error if (ptime==2) | (ptime==3), chi2 row


* Table 6.  Subversive Accretion Comparison
tabulate ptime cross_default_scope if (ptime==2) | (ptime==3), chi2  row
tabulate ptime neg_pledge_scope if (ptime==2) | (ptime==3), chi2  row
tabulate ptime pari_passu_scope if (ptime==2) | (ptime==3), chi2  row


****************************************************************************
****************************************************************************
** FIGURES
****************************************************************************
****************************************************************************
** graph incidence of the landmines by part of contract (Figure 1)

use "`pathdata'/sovereign data.dta", clear

gen law=governing_law
gen tgroup = ""
replace tgroup = "1960-85" if year<=1985 & year!=.
replace tgroup = "2020-2022" if year>=2020 & year<=2022 & year!=.
replace tgroup = "1990-1995" if year>=1990 & year<=1995 & year!=.
drop if tgroup==""

gen landmine1 = Form
gen landmine2 = Status
gen landmine3 = Negative_Pledge
gen landmine4 = Interest
gen landmine5 = Payments
gen landmine6 = Redemption
gen landmine7 = Taxation
gen landmine8 = Prescription
gen landmine9 = EventsofDefault
gen landmine10 = Agents
gen landmine11 = Notices
gen landmine12 = Modification
gen landmine13 = Further_Issues
gen landmine14 = Currency_Indemnity
gen landmine15 = GovLaw
gen landmine16 = Jurisdiction


keep index sovereign law landmine* year
reshape long landmine, i(index) j(landmineid)

gen section=""
replace section="Form" if landmineid==1
replace section="Status" if landmineid==2
replace section="Negative Pledge" if landmineid==3
replace section="Interest" if landmineid==4
replace section="Payments" if landmineid==5
replace section="Redemption" if landmineid==6
replace section="Taxation" if landmineid==7
replace section="Prescription" if landmineid==8
replace section="Events of Default" if landmineid==9
replace section="Agents" if landmineid==10
replace section="Notices" if landmineid==11
replace section="Modification" if landmineid==12
replace section="Further Issues" if landmineid==13
replace section="Currency Indemnity" if landmineid==14
replace section="Governing Law" if landmineid==15
replace section="Jurisdiction" if landmineid==16


*keep only 2020-2022
keep if (year>=2020) & (year<=2022) & (year!=.)

set scheme s2mono

* Figure 1 -- Parts of Contracts
graph hbar (mean) landmine, over(section, sort(1) label(labsize(small))) ///
blabel(bar, format(%4.2f)) ///
ytitle("") b1title("Fraction of Bonds") ///
graphregion(color(white))  ///
intensity(75) ///
note("Bonds collected randomly from 2020 to 2022")
graph export "`pathdata'/Figure 1.pdf", replace
*title("Incidence of Landmines by Contract Section")


****************************************************************************
****************************************************************************
** historical holdovers (Figure 2)

use "`pathdata'/sovereign data.dta", clear

gen law=governing_law
gen tgroup = ""
replace tgroup = "1960-85" if year<=1985 & year!=.
replace tgroup = "2020-2022" if year>=2020 & year<=2022 & year!=.
replace tgroup = "1990-1995" if year>=1990 & year<=1995 & year!=.
drop if tgroup==""


gen landmine1 = neg_pledge
gen landmine2 = buyback
gen landmine3 = pari_passu 


keep index sovereign law landmine* year
reshape long landmine, i(index) j(landmineid)



gen clause=""
replace clause="Negative Pledge" if landmineid==1
replace clause="Buy Back" if landmineid==2
replace clause="Pari Passu" if landmineid==3


keep if (year>=2020) & (year<=2022) & (year!=.)

set scheme s2mono

* Figure 2 -- historical holdovers
graph hbar (mean) landmine, over(clause, sort(1) label(labsize(small))) ///
blabel(bar, format(%4.2f)) ///
ytitle("") b1title("Fraction of Bonds") ///
graphregion(color(white))  ///
ysc(r(0,1)) yla(0(0.2)1) ///
intensity(75) ///
note("Bonds collected randomly from 2020 to 2022")
graph export "`pathdata'/Figure 2.pdf", replace
*title("Incidence of Historical Holdovers 2020-22") 



****************************************************************************
****************************************************************************
** subversive accretions (Figure 3)

use "`pathdata'/sovereign data.dta", clear

gen law=governing_law
gen tgroup = ""
replace tgroup = "1960-85" if year<=1985 & year!=.
replace tgroup = "2020-2022" if year>=2020 & year<=2022 & year!=.
replace tgroup = "1990-1995" if year>=1990 & year<=1995 & year!=.
drop if tgroup==""


gen landmine1 = pari_passu_mandlaw
gen landmine2 = fiscal_laws
gen landmine3 = glaw_authexec
gen landmine4 = sovereign_immunity_bylaw
gen landmine5 = jurisdiction
gen landmine6 = sovereign_immunity_exclusion
gen landmine7 = prescription
gen landmine8 = manifest_error

keep index sovereign law landmine* year

reshape long landmine, i(index) j(landmineid)


gen clause=""
replace clause="Pari Passu Mand Law" if landmineid==1
replace clause="Fiscal Laws" if landmineid==2
replace clause="Gov Law Auth Exec" if landmineid==3
replace clause="Sov Immunity By Law" if landmineid==4
replace clause="Jurisdiction" if landmineid==5
replace clause="Sov Immunity Exclusions" if landmineid==6
replace clause="Prescription" if landmineid==7
replace clause="Manifest Error" if landmineid==8

keep if (year>=2020) & (year<=2022) & (year!=.)

set scheme s2mono

* Figure 3 -- subversive accretions
graph hbar (mean) landmine, over(clause, sort(1) label(labsize(small))) ///
blabel(bar, format(%4.2f)) ///
ytitle("") b1title("Fraction of Bonds") ///
graphregion(color(white))  ///
ysc(r(0,1)) yla(0(0.2)1) ///
intensity(75) ///
note("Bonds collected randomly from 2020 to 2022")
graph export "`pathdata'/Figure 3.pdf", replace
*title("Incidence of Subversive Accretions 2020-2022") 



****************************************************************************
****************************************************************************
** periodic errors (Figure 4)
use "`pathdata'/sovereign data.dta", clear

gen law=governing_law
gen tgroup = ""
replace tgroup = "1960-85" if year<=1985 & year!=.
replace tgroup = "2020-2022" if year>=2020 & year<=2022 & year!=.
replace tgroup = "1990-1995" if year>=1990 & year<=1995 & year!=.
drop if tgroup==""


gen landmine1 = pari_passu_scope
gen landmine2 = neg_pledge_scope
gen landmine3 = cross_default_scope

keep index sovereign law landmine* year

reshape long landmine, i(index) j(landmineid)


gen clause=""
replace clause="Pari Passu Scope" if landmineid==1
replace clause="Neg Pledge Scope" if landmineid==2
replace clause="Cross Default Scope" if landmineid==3


keep if (year>=2020) & (year<=2022) & (year!=.)

set scheme s2mono

* Figure 4 -- subversive accretions
graph hbar (mean) landmine, over(clause, sort(1) label(labsize(small))) ///
blabel(bar, format(%4.2f)) ///
ytitle("") b1title("Fraction of Bonds") ///
graphregion(color(white))  ///
ysc(r(0,1)) yla(0(0.2)1) ///
intensity(75) ///
note("Bonds collected randomly from 2020 to 2022")
graph export "`pathdata'/Figure 4.pdf", replace
*title("Incidence of Periodic Errors 2020-2022") 


****************************************************************************
****************************************************************************
** periodic errors (Figure 3)

use "`pathdata'/sovereign data.dta", clear

gen law=governing_law
gen tgroup = ""
replace tgroup = "1960-85" if year<=1985 & year!=.
replace tgroup = "2020-2022" if year>=2020 & year<=2022 & year!=.
replace tgroup = "1990-1995" if year>=1990 & year<=1995 & year!=.
drop if tgroup==""



gen landmine1 = reverse_accel
gen landmine2 = glaw_always
gen landmine3 = cac_strategy_disclosure

keep index sovereign law landmine* year


reshape long landmine, i(index) j(landmineid)


gen clause=""
replace clause="Reverse Accel" if landmineid==1
replace clause="Gov Law Always" if landmineid==2
replace clause="CAC Strategy Disclosure" if landmineid==3


keep if (year>=2020) & (year<=2022) & (year!=.)

set scheme s2mono

* Figure 3 -- subversive accretions
graph hbar (mean) landmine, over(clause, sort(1) label(labsize(small))) ///
blabel(bar, format(%4.2f)) ///
ytitle("") b1title("Fraction of Bonds") ///
graphregion(color(white))  ///
ysc(r(0,1)) yla(0(0.2)1) ///
intensity(75) ///
note("Bonds collected randomly from 2020 to 2022")
graph export "`pathdata'/Figure 5.pdf", replace
*title("Incidence of Periodic Errors 2020-2022") 





